from typing import List

class Solution:
    def nextGreaterElements(self, nums: List[int]) -> List[int]:
        n, stack, ans = len(nums), [], [-1] * len(nums)
        for i in range(2 * n):
            num = nums[i % n]
            while stack and nums[stack[-1] % n] < num:
                popIdx = stack.pop()
                if popIdx < n:
                    ans[popIdx] = num
            stack.append(i)
        return ans